<template>
  <div class="container">
    <!-- 数据大屏展示内容区域 -->
    <div class="screen" ref="screen">
      <!-- 数据大屏顶部 -->
      <div class="top">
        <Top></Top>
      </div>
      <div class="bottom">
        <div class="left">
          <Tourist class="tourist"></Tourist>
          <Sex class="sex"></Sex>
          <Age class="age"></Age>
        </div>
        <div class="center">
          <Map class="chinese-map"></Map>
          <Line class="line"></Line>
        </div>
        <div class="right">
          <Rank class="rank"></Rank>
          <Year class="year"></Year>
          <Counter class="counter"></Counter>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入组件
import Top from './components/Top/index.vue'
import Tourist from './components/Tourist/index.vue'
import Sex from './components/Sex/index.vue'
import Age from './components/Age/index.vue'
import Map from './components/Map/index.vue'
import Line from './components/Line/index.vue'
import Rank from './components/Rank/index.vue'
import Year from './components/Year/index.vue'
import Counter from './components/Couter/index.vue'
// 设置组件名
defineOptions({
  name: 'Screen',
})

// 变量
let screen = ref()

// 生命周期钩子
onMounted(() => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
})

// 函数
// 计算数据大屏的缩放比列
function getScale(w = 1920, h = 1080) {
  const ww = window.innerWidth / w
  const wh = window.innerHeight / h
  return ww < wh ? ww : wh
}

// watch
// 监听视口的变化
window.onresize = () => {
  screen.value.style.transform = `scale(${getScale()}) translate(-50%,-50%)`
}
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url(./images/bg.png) no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    transform-origin: left top;

    .top {
      width: 100%;
      height: 40px;
    }

    .bottom {
      display: flex;
      height: 1040px;
      margin: 0 30px;

      .left {
        flex: 1;
        height: 100%;
        // 开启弹性布局
        display: flex;
        // 修改主轴方向 从上到下
        flex-direction: column;
        margin-right: 20px;

        .tourist {
          flex: 1.2;
        }

        .sex {
          flex: 1;
        }

        .age {
          flex: 1;
        }
      }

      .right {
        flex: 1;

        margin-left: 20px;
        margin-top: 20px;
        margin-bottom: 20px;
        // 开启弹性布局
        display: flex;
        // 修改主轴方向 从上到下
        flex-direction: column;
        .rank {
          flex: 1.2;
        }
        .year {
          flex: 1;
        }
        .counter {
          flex: 1;
        }
      }

      .center {
        flex: 2;
        height: 100%;
        display: flex;
        flex-direction: column;
        margin-bottom: 20px;
        justify-content: space-between;
        .chinese-map {
          flex: 4;
        }

        .line {
          flex: 1.4;
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>
